<!-- 气泡框组件 -->
<template>
  <div class="bubble-box">
    <div class="bubble-content">
      <slot></slot>
    </div>
    <svg class="bubble-angle" v-if="isAngle" :style="position" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 100" fill="transparent">
      <path d="M0,0 L100,100 L200,0"></path>
    </svg>
  </div>
</template>

<script>
export default {
  name: '',
  props: {
    direction: {
      type: String,
      default: 'bottom',
    },
    offset: {
      type: Number,
      default: 30,
    },
    isAngle: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      position: 'bottom: 0px;left: 30px;',
    };
  },
  mounted() {
    this.position = this.updatePosition(this.direction, this.offset);
  },
  methods: {
    updatePosition(direction, offset) {
      if (direction == 'bottom') {
        return 'bottom: -10px;left: ' + offset + 'px;transform: rotate(0deg);';
      } else if (direction == 'right') {
        return 'right: -10px;top: ' + offset + 'px;transform: rotate(-90deg);';
      } else if (direction == 'left') {
        return 'left: -10px;top: ' + offset + 'px;transform: rotate(90deg);';
      } else if (direction == 'top') {
        return 'top: -10px;left: ' + offset + 'px;transform: rotate(180deg);';
      } else {
        return 'bottom: -10px;left: ' + offset + 'px;transform: rotate(0deg);';
      }
    },
  },
  components: {},
  watch: {
    direction() {
      this.position = this.updatePosition(this.direction, this.offset);
    },
    offset() {
      this.position = this.updatePosition(this.direction, this.offset);
    },
  },
};
</script>

<style scoped>
.bubble-box {
  --bubble-background: #fff;
  background: var(--bubble-background);
  border-radius: 10px;
  position: relative;
}
.bubble-content {
  overflow: hidden;
  color: #000;
}
.bubble-angle {
  width: 20px;
  position: absolute;
}
.bubble-angle path {
  fill: var(--bubble-background);
}
</style>
